﻿using System;

namespace LearnFile3
{
    class Program
    {
        static void Main(string[] args)
        {
            JieCheng n = new JieCheng();
            Console.WriteLine("请输入数值：");
            int result = n.Jc(Convert.ToInt16(Console.ReadLine()));
            Console.WriteLine("result is {0}", result);
            Console.ReadKey();
            //While循环：
            Console.WriteLine("While循环：");
            int a = 10;
            while (a < 20)
            {
                Console.WriteLine("a的值为：{0}", a);
                a++;
            }
            Console.ReadLine();

            //for 循环执行
            Console.WriteLine("for循环：");
            for (int b = 10; b < 20; b = b + 1)
            {
                Console.WriteLine("b 的值： {0}", b);
            }
            Console.ReadLine();

            // foreach 循环
            Console.WriteLine("foreach 循环：");
            int[] fibarray = new int[] { 0, 1, 1, 2, 3, 5, 8, 13 };
            foreach (int element in fibarray)
            {
                System.Console.WriteLine(element);
            }
            System.Console.WriteLine();
            // 类似 foreach 循环
            for (int i = 0; i < fibarray.Length; i++)
            {
                System.Console.WriteLine(fibarray[i]);
            }
            System.Console.WriteLine();
            // 设置集合中元素的计算器
            int count = 0;
            foreach (int element in fibarray)
            {
                count += 1;
                System.Console.WriteLine("Element #{0}: {1}", count, element);
            }
            System.Console.WriteLine("Number of elements in the array: {0}", count);
        }
    }
    class JieCheng
    {
        public int Jc(int num)
        {
            // ?:运算符
            return num > 0 ? num * Jc(num - 1) : 1;
        }
    }
}
